package com.cty.C_SortAlgorithms.H_RadixSort;

import com.cty.F_common.DataItem;

/**
 * @Auther: cty
 * @Date: 2020/6/18 18:00
 * @Description: 双端链表
 * @version: 1.0
 */
public class FirstLastList {
    private Node first;
    private Node last;

    public FirstLastList(){
        first = null;
        last = null;
    }

    public boolean isEmpty(){
        return (first == null);
    }

    public void insertFirst(DataItem item){
        Node newNode = new Node(item);
        newNode.next = first;
        if(isEmpty())
            last = newNode;
        first = newNode;
    }

    public DataItem deleteFirst(){
        if(isEmpty())
            return null;

        DataItem temp = first.data;
        first = first.next;
        if(first == null)
            last = null;
        return temp;
    }

    public void insertLast(DataItem item){
        Node newNode = new Node(item);

        if(isEmpty())
            first = newNode;
        else
            last.next = newNode;
        last = newNode;
    }

}  // end FirstLastList{}
